﻿using Infrastructure.Interfaces;
using Microsoft.Practices.ServiceLocation;

namespace MVVMBasicRIALibrary
{
    public static class UnitOfWork
    {
        private static IUnitOfWorkFactory _unitOfWorkFactory;
        private static IUnitOfWork _unitOfWork;

        public static void Commit()
        {
            if (_unitOfWork != null)
            {
                _unitOfWork.Commit();
            }
        }

        public static IUnitOfWork Current 
        {
            get
            {
                if (_unitOfWork == null)
                {
                    _unitOfWorkFactory = ServiceLocator.Current.GetInstance<IUnitOfWorkFactory>();
                    _unitOfWork = _unitOfWorkFactory.Create();
                }
                return _unitOfWork;
            }
        }
    }
}
